<?php

namespace App\Http\Controllers;

use App\City;
use Illuminate\Http\Request;
use Overtrue\Pinyin\Pinyin;

class CityController extends Controller
{
    public function index(Request $request){
       $type = $request->type;
       $pinyin=new Pinyin();
       $city= City::where('parent_id',0)->get();
       $cityList=[];
       foreach ($city as $k=>$v){
            $cityList[$k]['city_id']=$v->id;
            $cityList[$k]['title']=$v->title;
            $cityList[$k]['is_hot']=$v->is_hot;
            $cityList[$k]['addr']=strtoupper(substr($pinyin->abbr($v->title),0,1));
        }
       $cityList= collect($cityList)->groupBy('addr')->toArray();
       return view('citylist',compact('cityList','city','type'));
    }
}
